---
sidebar_label: 矢量存储
sidebar_position: 3
---

# 入门: 矢量存储

:::info
[概念指南](https://docs.langchain.com/docs/components/indexing/vectorstore)
:::

矢量存储是一种专为存储文档及其[嵌入](../../models/embeddings/)而优化的数据库。接着，可以获取与查询最相关的文档，即嵌入与查询嵌入最相似的文档。

```typescript
interface VectorStore {

  /**

   * Add more documents to an existing VectorStore

   */

  addDocuments(documents: Document[]): Promise<void>;



  /**

   * Search for the most similar documents to a query

   */

  similaritySearch(

    query: string,

    k?: number,

    filter?: object | undefined

  ): Promise<Document[]>;



  /**

   * Search for the most similar documents to a query,

   * and return their similarity score

   */

  similaritySearchWithScore(

    query: string,

    k = 4,

    filter: object | undefined = undefined

  ): Promise<[object, number][]>;



  /**

   * Turn a VectorStore into a Retriever

   */

  asRetriever(k?: number): BaseRetriever;



  /**

   * Advanced: Add more documents to an existing VectorStore,

   * when you already have their embeddings

   */

  addVectors(vectors: number[][], documents: Document[]): Promise<void>;



  /**

   * Advanced: Search for the most similar documents to a query,

   * when you already have the embedding of the query

   */

  similaritySearchVectorWithScore(

    query: number[],

    k: number,

    filter?: object

  ): Promise<[Document, number][]>;

}

```


您可以从[文档列表](../../schema/document)或文本列表及其相应的元数据中创建矢量存储。您还可以从现有索引中创建矢量存储，此方法的签名取决于使用的矢量存储，请查看您感兴趣的矢量存储的文档。

```typescript
abstract class BaseVectorStore implements VectorStore {

  static fromTexts(

    texts: string[],

    metadatas: object[] | object,

    embeddings: Embeddings,

    dbConfig: Record<string, any>

  ): Promise<VectorStore>;



  static fromDocuments(

    docs: Document[],

    embeddings: Embeddings,

    dbConfig: Record<string, any>

  ): Promise<VectorStore>;

}

```


## 如何选择矢量存储？

以下是一个快速指南，帮助您选择适合您的用例的正确矢量存储:

- 如果您需要一种只能在Node.js应用程序内部运行的东西，即内存中，而不需要其他服务器，则选择[HNSWLib](./integrations/hnswlib)或[Faiss](./integrations/faiss)
- 如果您正在寻找一种可以在类似于浏览器的环境中内存中运行的东西，则选择[MemoryVectorStore](./integrations/memory)
- 如果您来自Python，并且正在寻找类似于FAISS的东西，则选择[HNSWLib](./integrations/hnswlib)或[Faiss](./integrations/faiss)
- If you're looking for an open-source full-featured vector database that you can run locally in a docker container, then go for [Chroma](./integrations/chroma)

- 如果您已经在使用Supabase，则可以查看[Supabase](./integrations/supabase)向量存储，以便对您的嵌入使用同一的Postgres数据库
- 如果您正在寻找一种不用自行托管的生产使用准备就绪的向量存储,请尝试[Pinecone](./integrations/pinecone)
- 如果您已经使用SingleStore,或者需要分布式，高性能数据库，您可能想考虑使用[SingleStore](./integrations/singlestore)向量存储。

## 所有向量存储

import DocCardList from "@theme/DocCardList";



<DocCardList />

